package edu.pku.sei.transformation.editor.parser.expression.element;

import java.util.ArrayList;

import edu.pku.sei.modeler.model.core.MetaModelElement;

public class FunctionExpression extends Expression {
	private Expression owner;
	private String id;
	private ArrayList<Expression> arguments;

	public FunctionExpression() {
		arguments = new ArrayList<Expression>();
	}

	@Override
	public String toString() {
		String s = new String();
		if (owner != null)
			s += owner.toString() + ".";
		s += id + "(";
		if (arguments.size() != 0) {
			for (int i = 0; i < arguments.size(); i++) {
				s += arguments.toString();
				if (i != arguments.size())
					s += ", ";
			}
		}
		return s;
	}

	public ArrayList<Expression> getArguments() {
		return arguments;
	}

	public void setArguments(ArrayList<Expression> arguments) {
		this.arguments = arguments;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Expression getOwner() {
		return owner;
	}

	public void setOwner(Expression owner) {
		this.owner = owner;
	}

	// public Element toXML(Element root) {
	// Element ele = root.addElement("function");
	// this.owner.toXML(ele.addElement("owner"));
	// ele.addAttribute("id", id);
	// for (int i = 0; i < arguments.size(); i++) {
	// arguments.get(i).toXML(ele);
	// }
	// return ele;
	// }
	@Override
	public boolean bind(Object context) {
		boolean result = true;
		for (Expression exp : arguments) {
			result = result && exp.bind(context);
		}
		return result;
	}

	@Override
	public MetaModelElement getType() {
		return null;
	}
}
